import java.util.ArrayList;

/**
 * Truck.java - Plug-in for hey0's minecraft mod.
 * @author Fugiman
 */
public class Truck {
	//Static references to the block ID's involved
    public static final int LAVA = 11;
    public static final int LIGHTSTONE = 89;
    public static final int OBSIDIAN = 49;
    public static final int IRON = 42;
    public static final int GOLD = 41;
    public static final int DIAMOND = 57;
    public static final int BUTTON = 77;
    public static final int LEVER = 69;
    public static final int LADDER = 65;
    //State variables
    private CardinalDirection direction;
    private SimpleLocation location;
    private ArrayList<Laser> lasers = new ArrayList<Laser>();

	@SuppressWarnings("deprecation")
	public Truck(Block block) {
		direction = CardinalDirection.fromButton(block.getData()).reverse();
		location = new SimpleLocation(block.getX(), block.getY(), block.getZ()).add(direction.reverse().toVector()).down();	
	}
	
	public boolean validate() {
		return (
				location.getBlockID() == GOLD &&
				location.move(CardinalDirection.SOUTH).getBlockID() == OBSIDIAN
		);
	}

	public synchronized void doWork() {
		for(Laser l : lasers) {
			l.doWork();
		}
		fire();
	}
	
	private void fire() {
		lasers.add(new Laser(location, direction));
	}
}
